package class71To80;

import java.io.*;
import java.util.*;

// 测试链接 : https://www.luogu.com.cn/problem/P1776
public class BoundedKnapsackWithBinarySplitting {

    public static int MAX_M = 40005;

    public static int MAX_N = 1005;

    public static int n, t, m, v, w, cnt;


    public static int[] values = new int[MAX_N];

    public static int[] dp = new int[MAX_M];

    public static int[] weights = new int[MAX_N];

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        while (in.nextToken() != StreamTokenizer.TT_EOF) {
            n = (int) in.nval;
            in.nextToken();
            t = (int) in.nval;
            m = 0;
            for (int i = 1; i <= n; i++) {
                in.nextToken();
                v = (int) in.nval;
                in.nextToken();
                w = (int) in.nval;
                in.nextToken();
                cnt = (int) in.nval;
                for (int k = 1; k <= cnt; k *= 2) {
                    values[++m] = k * v;
                    weights[m] = k * w;
                    cnt -= k;
                }
                if (cnt > 0) {
                    values[++m] = cnt * v;
                    weights[m] = cnt * w;
                }
            }
            out.println(solve());
        }
        out.flush();
        out.close();
        br.close();
    }

    // 时间复杂度O(t * (log(第1种商品的个数) + log(第2种商品的个数) + ... + log(第n种商品的个数)))
    // 对每一种商品的个数取log，所以时间复杂度虽然大于O(n * t)，但也不会大多少
    public static int solve() {
        Arrays.fill(dp, 0, t + 1, 0);
        for (int i = 1; i <= m; i++) {
            for (int j = t; j >= weights[i]; j--) {
                dp[j] = Math.max(dp[j], dp[j - weights[i]] + values[i]);
            }
        }
        return dp[t];
    }
}
